package com.care.mall.server.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.care.common.log.annotation.Log;
import com.care.common.log.enums.BusinessType;
import com.care.common.security.annotation.RequiresPermissions;
import com.care.mall.common.domain.MallImages;
import com.care.mall.server.service.IMallImagesService;
import com.care.common.core.web.controller.BaseController;
import com.care.common.core.domain.Result;
import com.care.common.core.utils.poi.ExcelUtil;
import com.care.common.core.web.page.TableDataInfo;

/**
 * 商品照片Controller
 *
 * @author 李光耀负责
 * @date 2024-03-27
 */
@RestController
@RequestMapping("/images")
public class MallImagesController extends BaseController
{
    @Autowired
    private IMallImagesService mallImagesService;

    /**
     * 查询商品照片列表
     */
    @RequiresPermissions("mall:images:list")
    @GetMapping("/list")
    public TableDataInfo list(MallImages mallImages)
    {
        startPage();
        List<MallImages> list = mallImagesService.selectMallImagesList(mallImages);
        return getDataTable(list);
    }

    /**
     * 导出商品照片列表
     */
    @RequiresPermissions("mall:images:export")
    @Log(title = "商品照片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallImages mallImages)
    {
        List<MallImages> list = mallImagesService.selectMallImagesList(mallImages);
        ExcelUtil<MallImages> util = new ExcelUtil<MallImages>(MallImages.class);
        util.exportExcel(response, list, "商品照片数据");
    }

    /**
     * 获取商品照片详细信息
     */
    @RequiresPermissions("mall:images:query")
    @GetMapping(value = "/{imageId}")
    public Result getInfo(@PathVariable("imageId") Long imageId)
    {
        return success(mallImagesService.selectMallImagesByImageId(imageId));
    }

    /**
     * 新增商品照片
     */
    @RequiresPermissions("mall:images:add")
    @Log(title = "商品照片", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody MallImages mallImages)
    {
        return toAjax(mallImagesService.insertMallImages(mallImages));
    }

    /**
     * 修改商品照片
     */
    @RequiresPermissions("mall:images:edit")
    @Log(title = "商品照片", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody MallImages mallImages)
    {
        return toAjax(mallImagesService.updateMallImages(mallImages));
    }

    /**
     * 删除商品照片
     */
    @RequiresPermissions("mall:images:remove")
    @Log(title = "商品照片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{imageIds}")
    public Result remove(@PathVariable Long[] imageIds)
    {
        return toAjax(mallImagesService.deleteMallImagesByImageIds(imageIds));
    }
}
